var khdScore;
var imgUrlID;
var price;
var crpopUuid;
var goodName;

$(function() {
	crpopUuid = GetParpam("crpopUuid");

	var data = "&crpopUuid="+crpopUuid;
	var url = urlfile + "corePointsProduct/views";
	ajaxTool("post",data,url,
		function error(XMLHttpRequest, textStatus, errorThrown,fnErr){
			alert("error:" + data);
		},
		function success(data){
			if(!data.success) {
				alert(data.errMsg);
			}else{
				$("#title").html(data.data.crpopTitle);
				$("#price").html("￥"+data.data.crpopFee);
				$("#repertory").html("库存：" + data.data.crpopStock);
				$("#content").html(data.data.crpopDesc);

				khdScore = data.data.khdScore;
				price = data.data.crpopFee;
				goodName = data.data.crpopTitle;
				if(data.data.list.length>0){
					imgUrlID = data.data.list[0].cratmUuid;
                    $('#goods_detail_pic').attr('src', urlfile + "coreAttachment/image/get/" + data.data.list[0].cratmUuid);
                }
			}
		}
	);
});

//立即购买
function goPay_btn() {
	validSession();
	if(!dataGet('isLogined')){
		dataSave("openId", "");
		dataSave("loginType", "favorable_home");
		nextView("../../../page/OAuthGetCodeLogin.html");
		return;
	}
	dataSave("goodName", goodName);
	nextView("../payView/storePay.html?khdScore=" + khdScore + "&imgUrlID=" + imgUrlID + "&price=" + price + "&crpopUuid="  +crpopUuid);
}

//加入购物车
function goCart_btn() {
	validSession();
	if(!dataGet('isLogined')){
		dataSave("openId", "");
		dataSave("loginType", "favorable_home");
		nextView("../../../page/OAuthGetCodeLogin.html");
		return;
	}
	var userUuid = dataGet("userUuid");	
	var data = "userId="+userUuid+"&goodsName="+goodName+"&goodsAmount=1&goodsPrice="+price+ "&goodsImg=" +imgUrlID+ "&khdScore=" +khdScore+ "&crpopUuid=" +crpopUuid;
	var url = urlfile + "coreShoppingCart/userCartAdd";
	ajaxTool("post",data,url,
		function error(XMLHttpRequest, textStatus, errorThrown,fnErr){
			alert("error:" + data);
		},
		function success(data){
			if(!data.success) {
				alert(data.errMsg);
			}else{
				nextView("../payView/storeCartPay.html");
			}
		}
	);
	
}
